﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Konves.Csv.Serialization
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class CsvFieldAttribute : CsvAttribute, ICsvSerializationInfo
    {
        private const string defaultFormat = "";

        public CsvFieldAttribute(string fieldName) : this(fieldName, defaultFormat) { }
        public CsvFieldAttribute(int fieldIndex) : this(fieldIndex, defaultFormat) { }
        public CsvFieldAttribute(string fieldName, int fieldIndex) : this(fieldName, fieldIndex, defaultFormat) { }
        public CsvFieldAttribute(string fieldName, string format)
        {
            this.FieldName = fieldName;
            this.UseIndex = false;
            this.Format = format;
        }
        public CsvFieldAttribute(int fieldIndex, string format)
        {
            this.FieldIndex = fieldIndex;
            UseIndex = true;
        }
        public CsvFieldAttribute(string fieldName, int fieldIndex, string format)
        {
            this.FieldName = fieldName;
            this.FieldIndex = fieldIndex;
            this.UseIndex = true;
            this.Format = format;
        }

        public string FieldName { get; private set; }
        public int FieldIndex { get; private set; }
        public string Format { get; private set; }
        public bool UseIndex { get; private set; }

        public override bool Ignore { get { return false; } }
    }

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class CsvIgnoreAttribute : CsvAttribute
    {
        public override bool Ignore { get { return true; } }
    }


    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public abstract class CsvAttribute : Attribute
    {
        public abstract bool Ignore { get; }
    }

    public interface ICsvSerializationInfo
    {
        string FieldName { get;  }
        int FieldIndex { get; }
        string Format { get; }
        bool UseIndex { get; }
    }

}
